package cn.itcast.concurrent.controller;

import cn.itcast.concurrent.service.MonitorService;
import cn.itcast.concurrent.vo.Info;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;

/**
 * className: MonitorController
 * description:
 * date: 2023/2/23-13:36
 * <p>
 * project: concurrent
 * package: cn.itcast.concurrent.controller
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
@RestController
public class MonitorController {
    public static ArrayBlockingQueue<Info> QUEUE = new ArrayBlockingQueue<>(30);

    @Autowired
    private MonitorService monitorService;

    @GetMapping("/info")
    public List<Info> info() {
        ArrayList<Info> infos = new ArrayList<>();
        QUEUE.drainTo(infos);
        return infos;
    }

    @GetMapping("/start")
    public void start() {
        monitorService.start();
    }

    @GetMapping("/stop")
    public void stop() {
        monitorService.start();
    }
}
